package com.openbravo.data.loader.dialect.MySQL;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DBSession;
import e.odbo.DB;

public class MySQL8 extends MySQL{
    private static String JDBCDriver="com.mysql.cj.jdbc.Driver";


    public static DB connectLocal(String user,String password,String database)throws BasicException{
        return connect("localhost",3306,database,user,password);
    }

    public static DB connect(String host, int port, String database, String user, String password)throws BasicException {
        try {
            Class.forName(JDBCDriver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new BasicException(e.getMessage());
        }
        String url = String.format("jdbc:mysql://%s:%d/%s?serverTimezone=UTC&useSSL=false", host, port, database);
        DBSession dbSession=new DBSession(url,user,password);
        return DB.getInstance(dbSession);
    }

    public static MySQL8 C() throws BasicException {
        try {
            Class.forName(JDBCDriver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new BasicException(e.getMessage());
        }
        return new MySQL8();
    }


    /*
       Hongkong、Asia/Shanghai或者Asia/Hongkong
     */
    public  MySQL8 serverTimezone(String serverTimezone){
        connectProp.put("serverTimezone",serverTimezone);
        return this;
    }

    public static class TYPE{

    }
}
